'''
https://www.nowcoder.com/practice/545544c060804eceaed0bb84fcd992fb
'''

import sys

def transfer(a):
    return 1 if a > 0 else -1 if a < 0 else 0

n = int(sys.stdin.readline())
nums = sys.stdin.readline().strip().split(' ')
nums = list(map(transfer, map(int, nums)))

dic = {0: -1}
sum = 0
ans = -1
for i, num in enumerate(nums):
    sum += num
    if sum in dic:
        ans = max(ans, i - dic[sum])
    if sum not in dic:
        dic[sum] = i
sys.stdout.write(str(ans))
